<template>
  <div>
    <basic-container>
      <avue-detail :option="detailOption" v-model="form"></avue-detail>
      <div>
        <el-button type="primary" @click="goBack">返 回</el-button>
      </div>
    </basic-container>
  </div>
</template>

<script>
import { detailOption } from "../../../const/crud/pds/merchant/buyerDetail";
import { buyerDetails } from "../../../api/saleb/buyerDetail";
export default {
  data() {
    return {
      detailOption: detailOption,
      form: {
        area: ""
      }
    };
  },
  // created() {
  //   let id = this.$route.query.id;
  //   console.log('created',id);
  //   this.fetchSupplyDetail(id);
  // },
  // updated() {
  //   let id = this.$route.query.id;
  //   console.log('updated',id);
  // },
 
  beforeRouteEnter(to, from, next) {
    console.log(to, from);
    next(vm => vm.fetchSupplyDetail(vm.$route.query.res.id));
  },
  methods: {
    // 请求参数
    fetchSupplyDetail(id) {
      let params = {
        buyerId: id
      };
      buyerDetails(params)
        .then(response => {
          this.form = response.data.data;
          this.form.position = this.form.address;
          // this.detailList = this.form.detailList;
          console.log(response);
        })
        .catch(() => {
          this.goBack();
        });
    },
    // 返回按钮
    goBack(time = 1000) {
      let that = this;
      setTimeout(function() {
        that.$store.commit("DEL_ONE_TAG", that.$route);
        that.$router.go(-1);
      }, time);
    }
  }
};
</script>

<style>
</style>